package com.gz.mylife.im;

import android.os.Parcel;
import android.os.Parcelable;
import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Property;
import net.tsz.afinal.annotation.sqlite.Table;
import net.tsz.afinal.annotation.sqlite.Transient;

/**
 * 聊天室的消息内容 
 * @author linwenming
 *
 */
@Table(name="tb_chatmessage")
public class ChatMessage implements Parcelable{

	// type = 1文字 2图片 3声音   jpush对应的t
	@Transient
	public static final int TYPE_TEXT = 1;
	@Transient
	public static final int TYPE_PHOTO = 2;
	@Transient
	public static final int TYPE_AUDIO = 3;
	
	// stete = 0正常的消息 1正在上传的消息 2失败的消息
	@Transient
	public static final int STATE_NORMAL = 0;
	@Transient
	public static final int STATE_UPLOADING = 1;
	@Transient
	public static final int STATE_FAILURE = 2;
	
	public ChatMessage() {
		// TODO Auto-generated constructor stub
	}
	
	@Id
	private int id;
	@Property
	private int roomid;
	@Property
	private int lastid;
	@Property
	private int uid;
	@Property
	private int gender;
	@Property
	private String nickname;
	@Property
	private String face;
	@Property
	private String content;
	@Property
	private String picture;
	@Property
	private int width;
	@Property
	private int height;
	@Property
	private String audio;
	@Property
	private long dateline;
	@Property
	private int showType;
	@Property
	private boolean isComMsg;
	@Property
	private String extend;  // 或者字段暂时放坛子和帖子id ，逗号分隔
	@Property
	private int tieType;
	@Property
	private int tieCount;
	@Property
	private String tieContent;
	@Property
	private String title;
	@Property
	private int currentUID;

	@Transient
	public boolean inShowTime;
	
	/**
	 * 发送消息\上传图片
	 * 0:正常的  1正在上传 2上传失败
	 */
	@Transient
	public int inMsgState;
	
	// 用于请求完成后绑定对象所在当前位置
	@Transient
	public String inUUID;
	
	

	public int getCurrentUID() {
		return currentUID;
	}

	public void setCurrentUID(int currentUID) {
		this.currentUID = currentUID;
	}

	public int getTieType() {
		return tieType;
	}

	public void setTieType(int tieType) {
		this.tieType = tieType;
	}

	public int getTieCount() {
		return tieCount;
	}

	public void setTieCount(int tieCount) {
		this.tieCount = tieCount;
	}

	public String getTieContent() {
		return tieContent;
	}

	public void setTieContent(String tieContent) {
		this.tieContent = tieContent;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getExtend() {
		return extend;
	}

	public void setExtend(String extend) {
		this.extend = extend;
	}
	
	public int getRoomid() {
		return roomid;
	}

	public void setRoomid(int roomid) {
		this.roomid = roomid;
	}
	
	public int getShowType() {
		return showType;
	}

	public void setShowType(int type) {
		this.showType = type;
	}

	public int getLastid() {
		return lastid;
	}

	public void setLastid(int lastid) {
		this.lastid = lastid;
	}

	public int getUid() {
		return uid;
	}

	public void setUid(int uid) {
		this.uid = uid;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getFace() {
		return face;
	}

	public void setFace(String face) {
		this.face = face;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public String getAudio() {
		return audio;
	}

	public void setAudio(String audio) {
		this.audio = audio;
	}

	public long getDateline() {
		return dateline;
	}

	public void setDateline(long dateline) {
		this.dateline = dateline;
	}

	public boolean isComMsg() {
		return isComMsg;
	}

	public void setComMsg(boolean isComMsg) {
		this.isComMsg = isComMsg;
	}
	
	public ChatMessage(Parcel source) {
		id = source.readInt();
		roomid = source.readInt();
		lastid =source.readInt();
		uid = source.readInt();
		gender = source.readInt();
		nickname= source.readString();
		face = source.readString();
		content = source.readString();
		picture = source.readString();
		width = source.readInt();
		height = source.readInt();
		audio = source.readString();
		dateline =source.readLong();
		showType = source.readInt();
		extend = source.readString();
		isComMsg =source.readInt() == 1? true:false;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(id);
		dest.writeInt(roomid);
		dest.writeInt(lastid);
		dest.writeInt(uid);
		dest.writeInt(gender);
		dest.writeString(nickname);
		dest.writeString(face);
		dest.writeString(content);
		dest.writeString(picture);
		dest.writeInt(width);
		dest.writeInt(height);
		dest.writeString(audio);
		dest.writeLong(dateline);
		dest.writeInt(showType);
		dest.writeString(extend);
		dest.writeInt((isComMsg?1:0));
	}
	
	public static final Parcelable.Creator<ChatMessage> CREATOR = new Creator<ChatMessage>() {
		
		@Override
		public ChatMessage[] newArray(int size) {
			return new ChatMessage[size];
		}
		
		@Override
		public ChatMessage createFromParcel(Parcel source) {
			return new ChatMessage(source);
		}
	};
	
	@Override
	public boolean equals(Object o) {
		if(o instanceof ChatMessage){
			if(lastid == ((ChatMessage)o).getLastid()){
				return true;
			}
		}
		return false;
	}
}
